#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_excipolar.info <<'%EOF%'
   cc_rsp_excipolar
   ----------------
   Molecule:         He in D2h
   Wave Function:    CCSD / aug-cc-pVDZ
   Test Purpose:     Excited states frequency-dependent polarizabilities
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_excipolar.mol <<'%EOF%'
BASIS
aug-cc-pVDZ
Helium             
small test basis
    1    3  Y  X  Z   1.00D-15
        2.0   1    
He    0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_excipolar.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCSD
.NSYM
 8
.THRENR
 1.0d-9
.THRLEQ
 1.0d-9
*CCEXCI
.NCCEXCI
 0 1 0 0 0 0 0 0
.THREXC
 1.0d-9
*CCEXLR
.OPERATOR
ZDIPLEN ZDIPLEN
.SELSTA
 2 1 2 1
.FREQUE
  1
 0.10
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_excipolar.check
cat >>cc_rsp_excipolar.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Final * HF energy: * \-2.8557046677" $log | wc -l`
CRIT2=`$GREP "Total MP2 * energy: * \-2.88266717" $log | wc -l`
CRIT3=`$GREP "Total CCSD * energy: * \-2.88954848" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=5
ERROR[1]="ENERGIES NOT CORRECT"

# CCSD excitation energy for 1. state in symmetry 2
# | ^1B2u |    1   |     1.0057496  |      27.36785  |    220736.521  |  96.32  | 
CRIT1=`$GREP "\| \^1B2u \|    1   \|     1\.00574..  \|      27\.3678.  \|    220736\....  \|  96.32" $log | wc -l`
TEST[2]=`expr $CRIT1` 
CTRL[2]=1
ERROR[2]="CCSD EXCITATION ENERGY IS NOT CORRECT"

# CCSD excited state polarizability for 1. state in symmetry 2
#             ZDIPLEN -0.1000   ZDIPLEN  0.1000     -1.089483 
#             ZDIPLEN  -.1000   ZDIPLEN   .1000     -1.089483 
CRIT1=`$GREP "ZDIPLEN ( \-|\-0)\.1000   ZDIPLEN  ( |0)\.1000     \-1\.089483" $log | wc -l`
TEST[3]=`expr $CRIT1` 
CTRL[3]=1
ERROR[3]="CCSD EXCITED STATE POLARIZABILITY IS NOT CORRECT"


PASSED=1
for i in 1 2 3
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
